<?php

namespace App\Trip\Plane\Variflight;

use Exception;
use GuzzleHttp\Exception\GuzzleException;

class FlightAware extends Variflight
{
    /**
     * @throws Exception
     */
    public function __construct()
    {
        parent::__construct();
        $this->business = 'aware';
        $this->url      = config('trip.airplane.variflight.flight_aware.api_url');
    }


    /**
     * 按航班号+日期查询
     * @throws GuzzleException
     * @throws Exception
     */
    public function queryByFlightNo(VariflightRequest $request)
    {
        $param = [
            'fnum' => $request->getFlightNo(),
            'date' => $request->getTripDate(),
        ];

        $from = $request->getFrom();
        $to   = $request->getTo();
        if ($from->getType() != $to->getType() || $to->getType() != 2) {
            throw new Exception("当前类型仅支持传入机场三字码");
        }

        return $this->query($param);
    }
}